package com.htandroid.htandroid.webservice;

import android.util.Xml;

import com.htandroid.htandroid.entity.Htzc_Pvouch;
import com.htandroid.htandroid.entity.Htzc_Pvouchs;

import org.json.JSONObject;
import org.xmlpull.v1.XmlPullParser;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

public class abXMLHtzcPvouchslist {

    /**
     * 解析评论xml信息
     *
     * @param content
     * @return
     */
    public static ArrayList<Htzc_Pvouchs> paraseCommentInfors(String content) {
        List<String> list = new ArrayList<String>();
        content = content.replace("Htzc_Pvouchs=anyType", "#=#");
        String[] strs = content.split("#=");
        for (int i = 0; i < strs.length; i++) {
            if (strs[i].contains("#")) {
                list.add(strs[i].replace("#", "").trim().replace(" ", ""));
            }
        }
        ArrayList<Htzc_Pvouchs> zcpdlist_detail = new ArrayList<Htzc_Pvouchs>();
        for (int i = 0; i < list.size(); i++) {
            if (i == list.size() - 1) {
                list.set(i, list.get(i).replace(";};};}", "\"}"));
            }
            list.set(i, list.get(i).replace(";};", "\"}").replace("=", "\":\"").replace(";", "\",\"").replace("{autoid", "{\"autoid"));
            try {
                Htzc_Pvouchs info = new Htzc_Pvouchs();
                JSONObject dataJson = new JSONObject(list.get(i));
                info.setAutoid(string2null(dataJson.getString("autoid")));
                info.setCvouchid(string2null(dataJson.getString("cvouchid")));
                info.setScardnum(string2null(dataJson.getString("scardnum")));
                info.setSassetnum(string2null(dataJson.getString("sassetnum")));
                info.setSassetname(string2null(dataJson.getString("sassetname")));
                info.setDblvalue(string2null(dataJson.getString("dblvalue")));
                info.setSdeptnum(string2null(dataJson.getString("sdeptnum")));
                info.setSdeptname(string2null(dataJson.getString("sdeptname")));
                info.setsStyle(string2null(dataJson.getString("sStyle")));
                info.setSsite(string2null(dataJson.getString("ssite")));
                info.setCuser(string2null(dataJson.getString("cuser")));
                info.setLbuildnum(string2null(dataJson.getString("lbuildnum")));
                info.setLnum(string2null(dataJson.getString("lnum")));
                info.setLdiffnum(string2null(dataJson.getString("ldiffnum")));
                info.setCreason(string2null(dataJson.getString("creason")));
                info.setDpdate(string2null(dataJson.getString("dpdate")));
                info.setIsup(string2null(dataJson.getString("isup")));
                info.setSuccount(string2null(dataJson.getString("succount")));
                info.setZccheckeddate(string2null(dataJson.getString("zccheckeddate")));
                info.setZccheckedname(string2null(dataJson.getString("zccheckedname")));
                zcpdlist_detail.add(info);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return zcpdlist_detail;
    }

    //函数作用是把null 转为空
    public static String string2null(String str) {
        String rtn = "";
        if (str == null || str.equals("null") || str.equals("anyType{}")) {
            rtn = "";
        } else {
            rtn = str;
        }
        return rtn;
    }
}
